package com.dferreira.languagesteach.helpers;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

import com.dferreira.languagesteach.R;
import com.dferreira.languagesteach.activities.PreferencesActivity;

/**
 * Created by dferreira on 5/28/14.
 * for LanguagesTeach
 */
public class GenericUI {

    public final static int RESULT_CORRUPTED_PACKAGE = 100;

    /**
     * Show a toast message to the user
     *
     * @param msg message to show
     */
    public static void showToastMsg(Context context, String msg) {
        Toast toast;

        toast = Toast.makeText(context, msg, Toast.LENGTH_LONG);
        toast.setGravity(Gravity.CENTER, 0, 0);
        toast.show();
    }

    /**
     * Inflates the menu
     *
     * @param menu The Menu to inflate into. The items and sub-menu will be
     *             added to this Menu.
     * @return always true
     */
    @SuppressWarnings("SameReturnValue")
    public static boolean onCreateOptionsMenu(Activity activity, Menu menu) {
        MenuInflater menuInflater = activity.getMenuInflater();
        menuInflater.inflate(R.menu.languages_menu, menu);
        return true;
    }

    /**
     * Called when an item from the menu is selected
     *
     * @param item menu item selected
     */
    public static void onOptionsItemSelected(Activity activity, MenuItem item) {
        Intent intent;

        switch (item.getItemId()) {
            case R.id.preferences:
                intent = new Intent(activity,
                        PreferencesActivity.class);
                activity.startActivity(intent);
                break;

            default:
                break;
        }
    }
}
